import { Component, OnInit } from '@angular/core';
import {FormControl} from "@angular/forms";
import {CamManageService} from "../../shared/service/cam-manage.service";

@Component({
  selector: 'app-cam-manage-search',
  templateUrl: './cam-manage-search.component.html',
  styleUrls: ['./cam-manage-search.component.css']
})
export class CamManageSearchComponent implements OnInit {

  public searchParam: FormControl = new FormControl();

  constructor(
    private camManageService:CamManageService
  ) { }

  ngOnInit() {

    //搜索框输入信息订阅
    this.searchParam.valueChanges
      .debounceTime(500)
      .subscribe(value=>{
        this.camManageService.searchEvent.emit(value);
      });

    //搜索框清空订阅
    this.camManageService.searchFreshEvent.subscribe(
      param => {
        if (param) {
          this.searchParam.patchValue("");
        }
      }
    );
  }

}
